CONTENTS | INDEX | PREV | NEXT
fileno
NAME
fileno - return file descriptor given a file pointer
SYNOPSIS
#include <stdio.h>
int fd = fileno(fp); (MACRO)
FILE *fp;
FUNCTION
The fileno() macro returns the file descriptor (open, close, read,
write) associated with the file pointer (fopen, fclose, fread,
fwrite).
This is still not the AmigaDOS file handle... to get that you must
use the fdtofh() call.
WARNING
If you use the file descriptor of a file pointer the file pointer
will get its seek position confused. Additionally, there might
be unflushed data in the file pointer's buffers that has not
been written out to the file descriptor yet. There also might
be unread input on the file pointer's input buffers already
read from the file descriptor.
NOTE
refer to the file_pointer manual page for general information
EXAMPLE
/*
* stdin defaults to file descriptor 0
* stdout defaults to file descriptor 1
* stderr defaults to file descriptor 2
*/
#include <stdio.h>
#include <assert.h>
main()
{
assert(fileno(stdin) == 0);
assert(fileno(stdout) == 1);
assert(fileno(stderr) == 2);
return(0);
}
INPUTS
FILE *fp; file pointer
RESULTS
int fd; associated file descriptor
SEE ALSO
fdopen, fopen, fclose, open, close